package com.ruoyi.logic.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.logic.service.ElectricityGenerationService;
import com.ruoyi.logic.vo.ElectricityVO;
import com.ruoyi.logic.vo.LineChartVO;
import org.apache.poi.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.concurrent.DelegatingSecurityContextExecutorService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/electricity/")
public class ElectricityGenerationController {

    @Autowired
    ElectricityGenerationService electricityGenerationService;

    @RequestMapping(value = "getTableData", method = RequestMethod.GET)
    public AjaxResult getTableData(@RequestParam String date, Integer offSetDay){
        DateTime startDate = DateUtil.parseDate(date);
        DateTime endDate = DateUtil.offsetDay(startDate, offSetDay);

        List<ElectricityVO> tableData = electricityGenerationService.getTableData(startDate,endDate);
        List<String> xAxis = tableData.stream().map(ElectricityVO::getDateTime).collect(Collectors.toList());
        List<String> yAxis = tableData.stream().map(item -> String.valueOf(item.getElectricityGenerationCapacity())).collect(Collectors.toList());
        LineChartVO lineChartVO = new LineChartVO("电力生成统计表",xAxis,yAxis);

        return AjaxResult.success(lineChartVO);
    }

}
